﻿using System;


namespace advadev.CanOpen
{

    /// <summary>
    /// Represents a can open time of day
    /// </summary>
    public class CanOpenTimeOfDay : CanOpenUnsigned
    {

        /// <summary>
        /// Initializes a new instance of the CanOpenTimeOfDay class by the
        /// given parameter
        /// </summary>
        /// <param name="index">
        /// Index of the object
        /// </param>
        /// <param name="subIndex">
        /// Sub index of the object
        /// </param>
        /// <param name="isReadable">
        /// Flag indicating whether the object is readable
        /// </param>
        /// <param name="isWriteable">
        /// Flag indicating whether the object is writeable
        /// </param>
        public CanOpenTimeOfDay(UInt16 index, byte subIndex, bool isReadable, bool isWriteable)
            : base(6, index, subIndex, isReadable, isWriteable)
        {
        }


        /// <summary>
        /// Gets or sets the milliseconds after midnight
        /// </summary>
        public uint Milliseconds
        {
            get
            {
                return (uint)(((ulong)Value & 0xFFFFFFF00000) >> 20);
            }
            set
            {
                Value = (ulong)((ulong)((ulong)value << 20) + (ulong)(Value & 0xFFFF));
            }
        }

        /// <summary>
        /// Gets or sets the days since January 1th, 1984
        /// </summary>
        public UInt16 Days
        {
            get
            {
                return (UInt16)(Value & 0xFFFF);
            }
            set
            {
                Value = (ulong)((ulong)(Value & 0xFFFFFFF00000) + (ulong)value);
            }
        }

    }

}
